package com.liu.map
{
	import com.liu.element.StaticSprite;
	
	import flash.display.Bitmap;
	import flash.display.BitmapData;
	import flash.display.Sprite;
	import flash.display.Stage;
	import flash.display3D.Context3D;
	import flash.events.Event;
	import flash.events.MouseEvent;
	import flash.geom.Point;
	import flash.geom.Rectangle;
	import flash.utils.getTimer;
	
	import org.ijelly.findPath.Cell;
	import org.ijelly.findPath.NavMesh;
	import org.ijelly.geom.Block;
	import org.molehill.SpriteBIGMoleHill;
	import org.molehill.SpriteMoleHill;
	
	public class MapContainer extends SpriteBIGMoleHill implements IResizeDisplayObject
	{
		private var _recW:int;
		private var _recH:int;
		private var _mapW:int;
		private var _mapH:int;
		private var _wNum:int;
		private var _hNum:int;
		
		private var _beginPoint:Point;
		
		public var mapManager:MapManager;
		public var nav:NavMesh;
		
		public var stage:Stage;
		
		public function MapContainer(context:Context3D,stage:Stage,mapManager:MapManager)
		{
			super(context);
			this.stage = stage;
			this.mapManager = mapManager;
			refreshStaticSpriteAry();
		}
		private function refreshStaticSpriteAry(event:Event = null):void{
			this._recW = this.viewRec.width = stage.stageWidth;
			this._recH = this.viewRec.height = stage.stageHeight;
			_wNum = Math.ceil(_recW/256) + 1;
			_hNum = Math.ceil(_recH/256) + 1;
		}
		
		public function refrushMap(center:Point):void{
			var tempx:int =  this._recW/2 - center.x;
			var tempy:int =  this._recH/2 - center.y;
			if(tempx > 0){
				tempx = 0;
			}else if(tempx < this._recW - _mapW){
				tempx = this._recW - _mapW;
			}
			
			if(tempy > 0){
				tempy = 0;
			}else if(tempy < this._recH - _mapH){
				tempy = this._recH - _mapH;
			}
			
			this.x = nav.x = tempx;
			this.y = nav.y = tempy;
			this.viewRec.x = -tempx;
			this.viewRec.y = -tempy;
			mapManager.onLoadkey(-tempx,-tempy,this._wNum,this._hNum);
		}
		
		public function resize():void
		{
			refreshStaticSpriteAry();
		}

		public function setMapWH(w:int,h:int):void{
			_mapW = w;
			_mapH = h;
		}


	}
}